import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class study {
    public static void main(String[] args) {
        JPanel panel = new JPanel();//面板

        JFrame frame = new JFrame("Brightness Control");

        //按钮
        JButton button = new JButton("Click me");
        button.setBounds(50,50,50,50);
        button.addActionListener(new ActionListener() {//设置监视器
            @Override
            public void actionPerformed(ActionEvent e) {//当被点击是要执行的行为
                System.out.println("yes");
            }
        });
        panel.add(button);
        frame.add(panel);
        frame.setVisible(true);
        frame.setBounds(9,300,4,4);
        frame.setSize(500, 300);
    }

    public static void main1(String[] args) {
        //滑块

        JFrame frame = new JFrame("Brightness Control");

        JPanel panel = new JPanel();//面板
//        panel.add()
        frame.add(panel);

        frame.setSize(200, 200);
//        frame.setDefaultCloseOperation();
        //获得一个
        JLabel brightnessLabel = new JLabel("Brightness: 50");// 下方标签

        JSlider brightnessSlider = new JSlider(0, 100, 50);//滑杆

        brightnessSlider.addChangeListener(new ChangeListener() {//添加变化监视
            @Override
            public void stateChanged(ChangeEvent e) {
                int val = brightnessSlider.getValue();//那么这个value就对应的是滑块对应的值了
                brightnessLabel.setText("Brightness: " + val);//设置标签的值
                //得到值了就达到了目的
            }
        });
        //设置窗口的属性

        JPanel jPanel = new JPanel();//面版,用来储存属性

        jPanel.add(brightnessSlider);//加入滑块到面板

        jPanel.add(brightnessLabel);//加入标签都面板

        frame.add(jPanel);//加入面板到最终的窗口中 这样窗口就有了属性

        frame.setSize(300, 200);

        frame.setVisible(true);//是否可见
    }
}
